package com.yuedou.api.service.sys.impl;

import com.yuedou.api.dao.sys.SysErrorMapper;
import com.yuedou.api.entity.sys.SysError;
import com.yuedou.api.service.base.impl.BaseServiceImpl;
import com.yuedou.api.service.sys.SysErrorService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;

@Service
public class SysErrorServiceImpl extends BaseServiceImpl<SysErrorMapper, SysError> implements SysErrorService {
    @Resource
    private SysErrorMapper dao;

    @Override
    public int insertSelective(String name,Exception e) {

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        e.printStackTrace(new PrintStream(baos));
        String exception = baos.toString();

        SysError record = new SysError();
        record.setName(name);
        record.setErrorContent(exception);
        return dao.insert(record);
    }
}
